package com.glory.dmegcpda.view

import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import com.glory.dmegcpda.R
import com.glory.dmegcpda.base.Constant
import com.glory.dmegcpda.databinding.ActivityCheckInfoBinding
import com.glory.dmegcpda.viewmodel.CheckInfoViewModel
import com.glory.mvvmnet.base.BaseActivity
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DateUtils
import kotlinx.android.synthetic.main.activity_check_info.*
import kotlinx.android.synthetic.main.activity_title.*

/**
 * FileName: CheckInfoActivity
 * Author: XJH
 * Date: 2021/10/21 15:51
 * Description:
 * History:
 */
class CheckInfoActivity : BaseActivity<CheckInfoViewModel>(),
    View.OnClickListener {
    var sheetRRN : String? = null
    var objectRRN : String? = null
    var binding : ActivityCheckInfoBinding? = null
    override fun layoutId(): Int {
        return R.layout.activity_check_info
    }

    override fun initView(savedInstanceState: Bundle?) {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_check_info)
        binding!!.checkInfoViewModel = viewModel
        val extras = intent.extras
        sheetRRN = extras?.getString("SHEETRRN", "")
        objectRRN = extras?.getString("OBJECTRRN", "")
        val eqpID = extras?.getString("EQPID", "")
        tvEqpID.text = eqpID
        tvCheckTime.text = FreeApi_DateUtils.getNowStringDate("yyyy/MM/dd HH:mm:ss")
        tvCheckPerson.setText(Constant.userName)
        tvTitle.text = "点检任务"

        viewModel.init(sheetRRN!!)
        rvCheckList.adapter = viewModel.mAdapter
        tvTemp.setOnClickListener(this)
        tvSave.setOnClickListener(this)
        ivBack.setOnClickListener { finish() }

    }

    override fun initData() {
        viewModel.defUI.startActivity.observe(this){
            setResult(RESULT_OK)
            finish()
        }
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.tvTemp ->{
                viewModel.save(tvCheckPerson.text.toString().trim(),"N",objectRRN!!)
            }
            R.id.tvSave ->{
                viewModel.save(tvCheckPerson.text.toString().trim(),"Y",objectRRN!!)
            }
        }
    }
}